package sd.qd.xiaoming.coffeedesk.service;

import java.lang.reflect.Field;
import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.transaction.annotation.Transactional;

import sd.qd.xiaoming.coffeedesk.dao.BaseDAO;
import sd.qd.xiaoming.coffeedesk.entity.BaseEntity;

@SuppressWarnings("rawtypes")
@Transactional
public class BaseService<D extends BaseDAO, E extends BaseEntity> implements InitializingBean {


	private BaseDAO<E> daoS;

	@SuppressWarnings("unchecked")
	@Override
	public void afterPropertiesSet() throws Exception {
		Field daoField = this.getClass().getDeclaredField("dao");
		daoField.setAccessible(true);
		this.daoS = (BaseDAO<E>) daoField.get(this);
	}

	public void delete(final E entity) {
		this.daoS.delete(entity);
	}

	public void delete(final E... entitys) {
		this.daoS.delete(entitys);
	}

	public List<E> findAll() {
		return this.daoS.findAll();
	}

	public E findById(final Long id) {
		return this.daoS.findById(id);
	}

	public E merge(final E entity) {
		return this.daoS.merge(entity);
	}

	public E[] merge(final E... entitys) {
		return this.daoS.merge(entitys);
	}

	public E save(final E entity) {
		return this.daoS.save(entity);
	}

	public E[] save(final E... entitys) {
		return this.daoS.save(entitys);
	}

	public E update(final E entity) {
		return this.daoS.update(entity);
	}

	public E[] update(final E... entitys) {
		return this.daoS.update(entitys);
	}


}
